using System.Collections.Generic;
using System.Data;
using System.IO;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;

namespace baiduNLP
{
  public class readExcel
  {
    public static List<WordModel> read(string filePath)
    {
      using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
      {
        List<WordModel> wordsList = new List<WordModel>();
        XSSFWorkbook hssfWorkbook = new XSSFWorkbook(fs);
        ISheet sheet = hssfWorkbook.GetSheetAt(0);
        int rowcount = sheet.LastRowNum;
        for (int i = 0; i < rowcount; i++)
        {
          IRow row = sheet.GetRow(i);
          wordsList.Add(new WordModel()
          {
            text = row.GetCell(0).ToString(),
            character = row.GetCell(1).ToString()
          });
        }
        return wordsList;
      }
    }
  }
}